#!/bin/bash
#(c) Copyright Barry Kauler 2009
#This is a GUI frontend for Woof.

set -a #export everything

WOOF_GUI=1

DEFAULTTABNUM="0"
[ $1 ] && DEFAULTTABNUM="$1"

. ./_00func

#Specifications
[ ! -f DISTRO_SPECS ] && exit
. ./DISTRO_SPECS
. ./DISTRO_PET_REPOS

source_compat_repos #sets DCRFILE
source_pkgs_specs   #sets DPSFILE
set_binaries_var    #ex: BINARIES="deb"

#run this stuff at first entry only...
ALLPS="`busybox ps`"
if [ "`echo "$ALLPS" | grep 'gtkdialog -i ./woof_gui_tabs'`" = "" ];then
 echo "$DISTRO_NAME" > /tmp/woof_gui_dn
 echo "$DISTRO_FILE_PREFIX" > /tmp/woof_gui_dfp
 echo "$DISTRO_COMPAT_VERSION" > /tmp/woof_gui_dcv
 echo "$PKG_DOCS_PET_REPOS" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_pkg_docs_pet_repos
 echo "$PET_REPOS" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_pet_repos
 xPKG_DOCS_PET_REPOS="$PKG_DOCS_PET_REPOS"
 echo "$REPOS_DISTRO_COMPAT" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_compat_repos
 COMPAT_REPOS="$REPOS_DISTRO_COMPAT" #alternate name used in this script.
 xCOMPAT_REPOS="$COMPAT_REPOS"
 echo "$PKG_DOCS_DISTRO_COMPAT" | sed -e 's% $%%' | tr ' ' '\n' > /tmp/woof_gui_pkg_docs_compat_repos
 PKG_DOCS_COMPAT_REPOS="$PKG_DOCS_DISTRO_COMPAT" #alternative name used in this script.
 xPKG_DOCS_COMPAT_REPOS="$PKG_DOCS_COMPAT_REPOS"
fi
xBUILD_FROM_WOOF="$BUILD_FROM_WOOF"

########Specifications tab#######
update_distro_specs_func() {
 . ./DISTRO_SPECS
 #change all the variables to template values...
 # dlg variables: xDISTRO_NAME xDISTRO_VERSION
 #   xDISTRO_BINARY_COMPAT xDISTRO_FILE_PREFIX xDISTRO_COMPAT_VERSION
 xDISTRO_XORG_AUTO="$DISTRO_XORG_AUTO" #110821
 xBUILD_FROM_WOOF="$BUILD_FROM_WOOF"

 nDFP=`echo -n "$xDISTRO_FILE_PREFIX" | wc -c`

 DPSFILE=''
 if [ -f DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION} ];then
  DPSFILE="DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}"
 else
  [ -f DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT} ] && DPSFILE="DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}"
 fi
 if [ "$DPSFILE" = "" ];then
  xmessage -center -bg red "ERROR:
The 'Packages' and later tabs need a configuration file named 'DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}',
which does not exist. This file has a table of what packages are to be included in the
build of Puppy. 
If there is a similarly-named file, 'DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-<something>',
a good starting point is to make a copy of it, named 'DISTRO_PKGS_SPECS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}'.

Aborting changes to file DISTRO_SPECS"
  return
 fi
 DCRFILE=''
 if [ -f DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION} ];then
  DCRFILE="DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}"
 else
  [ -f DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT} ] && DCRFILE="DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}"
 fi
 if [ "$DCRFILE" = "" ];then #130306
  xmessage -center -bg red "ERROR:
The 'Compat repos' and later tabs need a configuration file named 'DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}',
which does not exist. This file specifies the URLs where the compatible-distro packages
can be downloaded from. 
If there is a similarly-named file, 'DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-<something>',
a good starting point is to make a copy of it, named 'DISTRO_COMPAT_REPOS-${xDISTRO_BINARY_COMPAT}-${xDISTRO_COMPAT_VERSION}'.

Aborting changes to file DISTRO_SPECS"
  return
 fi
 cp -f DISTRO_SPECS /tmp/DISTRO_SPECS-backup
 echo '#One or more words that identify this distribution:' > DISTRO_SPECS
 echo "DISTRO_NAME='${xDISTRO_NAME}'" >> DISTRO_SPECS
 echo '#version number of this distribution:' >> DISTRO_SPECS
 echo "DISTRO_VERSION=${xDISTRO_VERSION}" >> DISTRO_SPECS
 echo '#The distro whose binary packages were used to build this distribution:' >> DISTRO_SPECS
 echo "DISTRO_BINARY_COMPAT='${xDISTRO_BINARY_COMPAT}'" >> DISTRO_SPECS
 echo '#Prefix for some filenames: exs: '"${xDISTRO_FILE_PREFIX}save.2fs, ${xDISTRO_FILE_PREFIX}-${xDISTRO_VERSION}.sfs" >> DISTRO_SPECS
 echo "DISTRO_FILE_PREFIX='${xDISTRO_FILE_PREFIX}'" >> DISTRO_SPECS
 echo '#The version of the distro whose binary packages were used to build this distro:' >> DISTRO_SPECS
 echo "DISTRO_COMPAT_VERSION='${xDISTRO_COMPAT_VERSION}'" >> DISTRO_SPECS
 if [ "$xDISTRO_XORG_AUTO" ];then #110821
  echo '#read by /usr/bin/xwin to bypass Xorg Wizard at first boot:' >> DISTRO_SPECS
  echo "DISTRO_XORG_AUTO='$xDISTRO_XORG_AUTO'" >> DISTRO_SPECS
 fi
 if [ "$xBUILD_FROM_WOOF" ];then
   echo "BUILD_FROM_WOOF='${xBUILD_FROM_WOOF}'" >> DISTRO_SPECS
 fi

 #121105 restore other variables that may have been in prior DISTRO_SPECS...
 for ONEDISTROVAR in `grep -o '^DISTRO_[^# =]*' /tmp/DISTRO_SPECS-backup | tr '\n' ' '`
 do
  odvPTN="^${ONEDISTROVAR}="
  if [ "`grep "$odvPTN" ./DISTRO_SPECS`" == "" ];then
   grep "$odvPTN" /tmp/DISTRO_SPECS-backup >> ./DISTRO_SPECS
  fi
 done

 Xdialog --center --title "DISTRO_SPECS" --backtitle "This is now the content of file 'DISTRO_SPECS'. Click OK button to continue" --no-cancel --textbox ./DISTRO_SPECS 0 0
}

ITEMSCOMP="<item>${DISTRO_BINARY_COMPAT}</item>"
for ONECHOICE in debian devuan puppy raspbian slackware ubuntu
do
 [ "$ONECHOICE" = "$DISTRO_BINARY_COMPAT" ] && continue
 ITEMSCOMP="${ITEMSCOMP}<item>${ONECHOICE}</item>"
done

edit_pet_repos() { defaulttextviewer DISTRO_PET_REPOS ; }
edit_compat_repos_func() { defaulttextviewer $DCRFILE ; }

#####Download dbs######
PET_REPOS_LIST_ONLINE="`echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | cut -f 2 -d '|' | sed 's%.*/%%' | sort -u`"
PET_REPOS_LIST_LOCAL="`ls -1 Packages-puppy-*`"
echo -n "" > /tmp/PET_REPOS_LIST_LOCAL
for ONE_DB in $PET_REPOS_LIST_LOCAL
do
 [ "`echo "$PET_REPOS_LIST_ONLINE" | grep "^${ONE_DB}$"`" != "" ] && echo "$ONE_DB" >> /tmp/PET_REPOS_LIST_LOCAL
done
PET_REPOS_LIST_LOCAL="`cat /tmp/PET_REPOS_LIST_LOCAL`"
PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | cut -f 3 -d '|' | sort -u`"
echo -n "" > /tmp/PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL
for ONE_DB in $PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE
do
 [ -f $ONE_DB ] && echo "$ONE_DB" >> /tmp/PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL
done
PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL="`cat /tmp/PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL`"
#in some cases, the "online" db is not available online. Then 1st and 2nd fields are empty...
PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | grep -v '||' | cut -f 3 -d '|' | sort -u`"

report_0setup_func() {
 if [ ! -f /var/woof/0setup_fail_report_no ];then
  xmessage -center -bg red "ERROR: Must run 'UPDATE' first"
  return
 fi
 xmessage -center -bg pink "`cat /var/woof/0setup_fail_report_no`"
}

check_dependencies_func() {
 xmessage "COMING SOON"
}

#######Download pkgs#####
download_summary_func() {
 xmessage "COMING SOON"
}

########Build pkgs########
CHOSEN_GENERICNAMES="`echo "$PKGS_SPECS_TABLE" | grep -v '^#' | grep '^yes' | cut -f 2 -d '|'`"
ITEMS_CG="<item>ALL_PACKAGES</item> `echo "$CHOSEN_GENERICNAMES" | sed -e 's%^%<item>%' -e 's%$%</item>%' | tr '\n' ' '`"

createpackages_summary_func() {
 xmessage "COMING SOON"
}

export MAIN_DIALOG="
<window title=\"Woof: the Puppy builder\" icon-name=\"gtk-preferences\" >
<vbox>
  <notebook page=\"${DEFAULTTABNUM}\" labels=\"Specifications|PET repos|Compat repos|Download dbs|Choose pkgs|Download pkgs|Build pkgs|Build distro\">
    
    <vbox>
      <text use-markup=\"true\"><label>\"<b>These are the highest-level settings for building Puppy</b>\"</label></text>
      <hbox>
        <text><label>A title for this build:</label></text>
        <entry>
          <input>cat /tmp/woof_gui_dn</input>
          <variable>xDISTRO_NAME</variable>
        </entry>
        <text><label>\"(Any title, one to three words)\"</label></text>
      </hbox>
      <hbox>
        <text><label>Puppy version number:</label></text>
        <entry>
          <default>${DISTRO_VERSION}</default>
          <variable>xDISTRO_VERSION</variable>
        </entry>
        <text><label>(use dots to separate: major.minor[.subminor...] ex: 5.1.23)</label></text>
        <text><label>\"                     \"</label></text>
      </hbox>
      <hbox>
        <text><label>File prefix:</label></text>
        <entry>
          <input>cat /tmp/woof_gui_dfp</input>
          <variable>xDISTRO_FILE_PREFIX</variable>
        </entry>
        <text><label>\"(one to four characters only)\"</label></text>
      </hbox>
      <hbox>
        <text>
          <label>Compatible-distro:</label>
        </text>
	    <combobox>
          <variable>xDISTRO_BINARY_COMPAT</variable>
          ${ITEMSCOMP}
        </combobox>
        <text><label>(this the distro where to get the binary pkgs from)</label></text>
        <text><label>\"                     \"</label></text>
      </hbox>
      <hbox>
        <text><label>Compatible-distro version:</label></text>
        <entry>
          <input>cat /tmp/woof_gui_dcv</input>
          <variable>xDISTRO_COMPAT_VERSION</variable>
        </entry>
        <text><label>\"(a word or number)\"</label></text>
      </hbox>

      <hbox>
        <text><label>Welcome! Each of these tabs is a GUI frontend for a single configuration file or script. This first tab is a GUI for configuration file 'DISTRO_SPECS'. This file has the overall specifications for your proposed build of Puppy.</label></text>
        <text use-markup=\"true\"><label>\"<b>If any changes made above, click 'UPDATE' button to save changes:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Introduction</label><action>defaulttextviewer ./README.TXT & </action></button>
        <button><label>UPDATE OVERALL SPECS</label><action>update_distro_specs_func</action><action type=\"exit\">UPDATE_DS</action></button>
      </hbox>
      <hbox><text><label>\"       \"</label></text></hbox>
      <hbox>
        <button><label>_00build.conf</label><action>defaulttextviewer ./_00build.conf & </action></button>
        <text><label>This file has persistent configuration options for your build</label></text>
        <text><label>\"       \"</label></text>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>These are the online repositories of PET packages</b>\"</label></text>
        <text><label>Even if you are building Puppy from some other compatible-distro, still many PET packages are required</label></text>
      </hbox>
      <tree>
        <label>URL|Local database file(s)</label>
        <input>cat /tmp/woof_gui_pet_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_PET_REPOS</variable>
      </tree>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>Online PET database files</b>\"</label></text>
        <text><label>The up-to-date PET database files are online, for Woof to download</label></text>
      </hbox>
      <tree>
        <label>URL of online database file (the same name as the local db files)</label>
        <input>cat /tmp/woof_gui_pkg_docs_pet_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_PKG_DOCS_PET_REPOS</variable>
      </tree>
      <hbox>
        <text><label>This tab is a GUI for configuration file 'DISTRO_PET_REPOS'.</label></text>
        <text use-markup=\"true\"><label>\"<b>If any changes made to the file, click 'UPDATE' button to reload</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Repositories</label><action>defaulthtmlviewer /usr/local/petget/README-add-repo.htm & </action></button>
        <button><label>Edit DISTRO_PET_REPOS</label><action>edit_pet_repos</action><action type=\"refresh\">TREE_PKG_DOCS_PET_REPOS</action></button>
        <button><label>UPDATE LIST</label><action type=\"exit\">UPDATE_PR</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>These are the online repositories of compatible-distro (${DISTRO_BINARY_COMPAT}) packages</b>\"</label></text>
        <text><label>This tab specifies the URLs for downloading the binary packages of ${DISTRO_BINARY_COMPAT}, release ${DISTRO_COMPAT_VERSION}, that you want to build Puppy from.</label></text>
      </hbox>
      <tree>
        <label>URL|Local database file(s)</label>
        <input>cat /tmp/woof_gui_compat_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_COMPAT_REPOS</variable>
      </tree>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>Online compat-distro database files</b>\"</label></text>
        <text><label>The up-to-date compat-distro database files are online, for Woof to download</label></text>
      </hbox>
      <tree>
        <label>URL of online database file|Local database file</label>
        <input>cat /tmp/woof_gui_pkg_docs_compat_repos | tr '\n' ' ' | sed -e 's%\n$%%' | tr ' ' '\n' | cut -f 2,3 -d '|'</input>
        <variable>TREE_PKG_DOCS_COMPAT_REPOS</variable>
      </tree>
      <hbox>
        <text><label>This tab is a GUI for configuration file '${DCRFILE}'.</label></text>
        <text use-markup=\"true\"><label>\"<b>If any changes made to the file, click 'UPDATE' button to save:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Repositories</label><action>defaulthtmlviewer /usr/local/petget/README-add-repo.htm & </action></button>
        <button><label>Edit ${DCRFILE}</label><action>edit_compat_repos_func</action><action type=\"refresh\">TREE_PKG_DOCS_COMPAT_REPOS</action></button>
        <button><label>UPDATE LIST</label><action type=\"exit\">UPDATE_CR</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <text use-markup=\"true\"><label>\"<b>This tab is for downloading the package databases</b>\"</label></text>
      <text><label>This tab is a frontend for script '0setup'</label></text>
      <hbox>
        <text><label>The left frame shows the database files as they would be named after downloading and converting to Puppy Standard Format (the actual online files are named differently). The right frame shows what is actually available locally.</label></text>
        <text><label>Note: the PET pkgs online databases are already in Puppy Standard Format, so only need to be downloaded. -- if any are missing, or you want to update them, click the UPDATE button</label></text>
      </hbox>
      <hbox>
        <frame PET pkg online databases><text><label>\"${PET_REPOS_LIST_ONLINE}\"</label></text></frame>
        <frame PET pkg local databases><text><label>\"${PET_REPOS_LIST_LOCAL}\"</label></text></frame>
      </hbox>
      <hbox>
        <frame compat-distro pkg online databases><text><label>\"${PKG_DOCS_DISTRO_COMPAT_LIST_ONLINE}\"</label></text></frame>
        <frame compat-distro pkg local databases><text><label>\"${PKG_DOCS_DISTRO_COMPAT_LIST_LOCAL}\"</label></text></frame>
      </hbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>Click 'UPDATE' if any files missing in right panes, or need updating:</b>\"</label></text>
        <text use-markup=\"true\"><label>\"<b>Report on last update:</b>\"</label></text>
      </hbox>
      <hbox>
        <button><label>Help: Standard DB Format</label><action>defaulthtmlviewer http://puppylinux.com/woof/pkg-db-format.htm & </action></button>
        <button><label>UPDATE LOCAL DB FILES</label><action type=\"exit\">UPDATE_DB</action></button>
        <button><label>REPORT</label><action>report_0setup_func</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <text use-markup=\"true\"><label>\"<b>This tab is for choosing what packages you want to have in the Puppy build</b>\"</label></text>
      <text><label>This tab is a frontend for config file '${DPSFILE}'</label></text>
      <hbox>
        <text><label>You can choose either PET packages or from the compat-distro (${DISTRO_BINARY_COMPAT}, release ${DISTRO_COMPAT_VERSION}). Of course, if you choose a Puppy-release as the compat-distro then they will also be PET packages.</label></text>
        <text><label>    Click on HELP to get more info about syntax, etc.    </label></text>
      </hbox>
      <hbox><text><label>\"         \"</label></text>
        <button><label>HELP</label><action>defaulttextviewer README.pkgs_specs & </action></button>
        <button><label>Edit ${DPSFILE}</label><action>defaulttextviewer ./${DPSFILE} & </action></button>
        <text><label>\"          \"</label></text>
      </hbox>
    </vbox>
    
    <vbox>
      <text use-markup=\"true\"><label>\"<b>This tab is for downloading the PET and compat-distro packages needed to build the Puppy live-CD</b>. This tab is a frontend for script '1download'\"</label></text>
      <hbox>
        <text><label>Assuming that at some prior stage the package database files were downloaded (see 'Download dbs' tab), the packages can now be downloaded. The PET packages will be downloaded to directory 'packages-pet' and the compat-distro packages to 'packages-${BINARIES}'.</label></text>
        <text><label>NOTE: It is allowed to manually copy a pkg into those directories. If you have a package that you have already added via 'Choose pkgs', you can manually place a PET package into 'packages-pet' and a compat-distro package into 'packages-${BINARIES}'. In that case, no need to click the above buttons.</label></text>
      </hbox>
      <hbox>
        <text><label>Click the button to download packages. Note that if packages already exist in those directories, they will not be re-downloaded, so you can click this button to download any packages that have been added in the 'Choose pkgs' tab since the last download...</label></text>
        <text><label>Click 'REPORT' button after downloading, for a summary. Sometimes things can go wrong, like the package no longer being available online, or the repository servers are offline, so it is wise to check. Note, sometimes clicking the 'DOWNLOAD' button again will succeed in getting missed pkgs.</label></text>
      </hbox>
      <hbox>
        <button><label>DOWNLOAD PACKAGES</label><action>rxvt -title \"Downloading packages\" -bg yellow -e ./1download</action><action>xmessage -bg green -center \"Download finished. Click 'REPORT' button (in 'Download pkgs' tab) for download summary\"</action><action type=\"exit\">UPDATE_DP</action></button>
        <button><label>REPORT</label><action>download_summary_func</action></button>
      </hbox>
    </vbox>
    
    <vbox>
      <hbox>
        <text use-markup=\"true\"><label>\"<b>This tab is for creating the cut-down packages needed to build a Puppy live-CD</b>. This tab is a frontend for script '2createpackages'\"</label></text>
        <text><label>You must have previously downloaded all the packages, see 'Download pkgs' tab. Now, they need to be processed into a cut-down and Puppy-compatible format. The resulting packages are created in directory 'packages-${DISTRO_FILE_PREFIX}'</label></text>
      </hbox>
      <hbox>
        <text><label>'ALL_PACKAGES' means all chosen packages (see 'Choose pkgs' tab) are processed, directory 'packages-${DISTRO_FILE_PREFIX}' is wiped and all packages re-created. 'CHANGED_ONLY' will automatically process only packages that have changed or added since last time 2createpackages was run. Or, if only one package has been added or modified in the 'Choose pkgs' tab, then it can be explicitly selected here to process just that one:</label></text>
        <combobox><variable>CHOICE_CREATEPACKAGES</variable>${ITEMS_CG}</combobox>
      </hbox>
      <hbox>
        <text><label>Click this button to build all the packages in directory 'packages-${DISTRO_FILE_PREFIX}', or the single package selected above:</label></text>
        <vbox>
          <button><label>CREATE PACKAGES</label><action>rxvt -title \"Creating packages\" -bg yellow -e ./2createpackages \$CHOICE_CREATEPACKAGES</action><action>xmessage -bg green -center \"Finished. Click 'REPORT' button for a summary.\"</action></button>
        </vbox>
      </hbox>
      <hbox>
        <text><label>Click 'REPORT' button afterward, for a summary. This can be useful to check that the right 'raw' binary packages were processed:</label></text>
        <vbox>
          <button><label>REPORT</label><action>createpackages_summary_func</action></button>
        </vbox>
      </hbox>
    </vbox>
    
    <vbox>
      <text use-markup=\"true\"><label>\"<b>This tab is for building the live-CD and 'devx' file</b>\"</label></text>
      <text><label>This tab is a frontend for script '3builddistro'</label></text>
      <hbox>
        <text><label>'${DISTRO_NAME}' version '${DISTRO_VERSION}' live-CD will be created, built from the packages of compatible-distro '${DISTRO_BINARY_COMPAT}' (release ${DISTRO_COMPAT_VERSION}).</label></text>
        <text><label>After making appropriate choices above, click here to build live-CD.</label></text>
      </hbox>
      <hbox><text><label>\"       \"</label></text></hbox>
      <button><label>BUILD DISTRO</label><action>rxvt -title \"Building distro\" -bg yellow -e ./3builddistro-Z </action></button>
      <hbox><text><label>\"       \"</label></text></hbox>
      <hbox>
        <button><label>_00build.conf</label><action>defaulttextviewer ./_00build.conf & </action></button>
        <text><label>This file has persistent configuration options for your build</label></text>
        <text><label>\"       \"</label></text>
      </hbox>
    </vbox>

  </notebook>

</vbox>
</window>"

#----------------------------------------------------------
# Main

eval "$(gtkdialog --program=MAIN_DIALOG)"

REENTER=''
case "$EXIT" in
   UPDATE_DS) DEFAULTTABNUM="0" ; REENTER=1 ;; #'Specifications' tab.
   UPDATE_PR) DEFAULTTABNUM="1" ; REENTER=1 ;; #'PET repos' tab.
   UPDATE_CR) DEFAULTTABNUM="2" ; REENTER=1 ;; #'Compat repos' tab.
   UPDATE_DB) #'Download dbs' tab.
    rxvt -bg yellow -title "Update databases" -e ./0setup
     DEFAULTTABNUM="3"
     REENTER=1
   ;;
   UPDATE_DP) DEFAULTTABNUM="5" ; REENTER=1 ;; #see 'Download pkgs' tab.
esac

[ "$REENTER" ] && exec $0 $DEFAULTTABNUM

### END ###